<template>
	<view class="kickback_record_container">
		<view class="kickback_record_box" v-if="kickbackList.length !==0">
			<!-- tab -->
			<u-tabs :list="tabList" :is-scroll="false" :current="currentTab" @change="changeTab"
				style="font-family: all-font;"></u-tabs>

			<view class="kickback_record_all" v-for="(item, index) in kickbackList" :key="index">
				<view class="kickback_top_box">
					<view class="kickback_top_tip">
						佣金来源：<span v-if="item.source == '0'">代理分佣</span>
						<span v-else-if="item.source == '1'">合伙人分佣</span>
						<span v-else-if="item.source == '2'">分销员分佣</span>
						<span v-else-if="item.source == '3'">提现</span>
						<span v-else-if="item.source == '4'">其他</span>
					</view>
					<view class="kickback_top_date">
						时间：<span style="font-family: my-font;">{{ item.created_at ? item.created_at : '' }}</span>
					</view>
				</view>
				<view class="kickback_bottom_box" style="padding-top: 12rpx;">
					<view class="kickback_bottom_order">
						用户名：{{ item.name ? item.name : '' }}
					</view>
					<view class="kickback_top_date">
						用户分类：{{ item.is_agent == 1 ? '合伙人' : '分销员' }}
					</view>
				</view>

				<view class="kickback_bottom_box" style="padding-top: 12rpx;">
					<view class="kickback_bottom_order">
						订单号：<span style="font-family: my-font;">{{ item.order_no ? item.order_no : '' }}</span>
					</view>
					<view class=""
						:class="[item.status == '0' ? 'kickback_bottom_num_up' : 'kickback_bottom_num_down']">
						<span>{{item.status == '0' ? '+' : '-'}}</span>{{ item.balance }}
					</view>
				</view>
				<view class="kickback_bottom_box" style="padding-top: 12rpx;" v-if="item.remark">
					<view class="kickback_bottom_order">
						佣金备注：{{ item.remark }}
					</view>
				</view>
			</view>
		</view>

		<!-- 没有订单 -->
		<view class="kickback_record_no_box" v-else>
			您还未获得佣金，快去推广吧~
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				kickbackList: [],
				pageObj: {
					pageNow: 1,
					pageSize: 10
				},
				total: 0,
				currentTab: 0,
				tabList: [{
						name: '全部'
					},
					{
						name: '我的'
					}
				],
				selectUserId: ''
			}
		},
		onShow() {
			if (this.pageObj.pageNow == this.total) {
				return
			} else {
				this.getBrokerageRecords()
			}
		},
		onReachBottom() {
			if (this.pageObj.pageNow < this.total) {
				this.pageObj.pageNow++
				this.getBrokerageRecords()
			} else if (this.pageObj.pageNow == this.total) {
				uni.showToast({
					title: '暂无更多数据',
					icon: 'none'
				})
				return
			}
		},
		methods: {
			// 切换tab
			changeTab(index) {
				this.currentTab = index
				if (this.currentTab == 0) {
					this.selectUserId = ''
					this.kickbackList = []
					this.getBrokerageRecords()
				} else {
					let userInfo = uni.getStorageSync('userInfo')
					this.selectUserId = userInfo.id
					this.kickbackList = []
					this.getBrokerageRecords()
				}
			},

			//source： 1合伙人分佣/2分销员分佣/3提现
			// status:0增;1减
			// 获取佣金记录
			getBrokerageRecords() {
				this.$request('/api/getYjRecordList', {
					// is_agent: '1', // 0分销员，1合伙人
					select_user_id: this.selectUserId,
					agent_level: '0',
					user_id: uni.getStorageSync('userInfo').id,
					page_now: this.pageObj.pageNow,
					page_size: this.pageObj.pageSize
				}, 'GET').then(res => {
					if (res.code == 1) {
						res.data.forEach(item => {
							this.kickbackList.push(item)
						})

						this.total = res.page_info.page_count
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						return
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.kickback_record_container {
		padding: 16rpx 20rpx 0;

		.kickback_record_box {

			.kickback_record_all {
				background: #FFFFFF;
				box-shadow: 0px 5rpx 4rpx 0px rgba(244, 244, 244, 0.54);
				border-radius: 12rpx;
				padding: 18rpx 23rpx 22rpx 31rpx;
				margin-bottom: 12rpx;

				.kickback_top_date {
					font-family: all-font;
					font-weight: normal;
					font-size: 24rpx;
					color: #808080;
				}

				.kickback_top_box {
					display: flex;
					justify-content: space-between;

					.kickback_top_tip {
						background: #FFF4F4;
						border-radius: 6rpx;
						font-family: all-font;
						font-weight: 400;
						font-size: 26rpx;
						color: #FF2E2E;
						padding: 4rpx 14rpx;
					}
				}

				.kickback_bottom_box {
					display: flex;
					justify-content: space-between;
					padding-top: 39rpx;

					.kickback_bottom_order {
						font-family: all-font;
						font-weight: 500;
						font-size: 30rpx;
						color: #333333;
					}

					.kickback_bottom_num_down {
						font-family: my-font;
						font-weight: 500;
						font-size: 28rpx;
						color: #00c482;
					}

					.kickback_bottom_num_up {
						font-family: my-font;
						font-weight: 500;
						font-size: 28rpx;
						color: #FF1B1B;
					}
				}
			}
		}


		.kickback_record_no_box {
			font-size: 40rpx;
			color: #ccc;
			font-family: all-font;
			text-align: center;
			padding-top: 30rpx;
		}
	}
</style>